package action;

import java.io.FileInputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_date_ben.EnitityBeanOc_Date_Ben;
import entitybean.oc_date_ice.EnitityBeanOc_Date_Ice;
import entitybean.oc_date_pla.EnitityBeanOc_Date_Pla;
import entitybean.oc_date_sur.EnitityBeanOc_Date_Sur;
import entitybean.oc_depthlist.EntityBeanOc_Depthlist;
import entitybean.oc_depthlist_ben.EntityBeanOc_Depthlist_Ben;
import entitybean.oc_depthlist_ice.EntityBeanOc_Depthlist_Ice;
import entitybean.oc_depthlist_pla.EntityBeanOc_Depthlist_Pla;
import entitybean.oc_property.EntityBean_Oc_Property;
import entitybean.oc_property_ben.EntityBean_Oc_Property_Ben;
import entitybean.oc_property_ice.EntityBean_Oc_Property_Ice;
import entitybean.oc_property_pla.EntityBean_Oc_Property_Pla;
import entitybean.oc_property_tools.EntityBean_Oc_Property_Tools;
import entitybean.oc_property_tools_ben.EntityBean_Oc_Property_Tools_Ben;
import entitybean.oc_property_tools_ice.EntityBean_Oc_Property_Tools_Ice;
import entitybean.oc_property_tools_pla.EntityBean_Oc_Property_Tools_Pla;
import entitybean.oc_station.EntityBeanOc_Station;
import entitybean.oc_station_ben.EntityBeanOc_Station_Ben;
import entitybean.oc_station_ice.EntityBeanOc_Station_Ice;
import entitybean.oc_station_pla.EntityBeanOc_Station_Pla;
import entitybean.oc_voyage.EnitityBeanOc_Voyage;
import entitybean.oc_voyage_ben.EnitityBeanOc_Voyage_Ben;
import entitybean.oc_voyage_ice.EnitityBeanOc_Voyage_Ice;
import entitybean.oc_voyage_pla.EnitityBeanOc_Voyage_Pla;
import entitybean.oc_xls_upload.Oc_Xls_Upload;
import form.DataForm;
import form.DataRecoverForm;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import tools.InterfaceForResultSetToList;
import tools.PageBeanPlus;
import view.ViewOc_Data;
import view.ViewOc_Data_Recover;

public class Action_Oc_Data_Recover extends DispatchAction {
	private Service_Admin service_admin;
	private Service_Public service_public;

	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin serviceAdmin) {
		service_admin = serviceAdmin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public servicePublic) {
		service_public = servicePublic;
	}

	public ActionForward admin_init_import_recover(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataRecoverForm datarecoverform = (DataRecoverForm) form;
		String sql = "select * from OC_XLS_UPLOAD order by id DESC";
		System.out.println("SQL=" + sql);
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(datarecoverform.getRowcountperpage()), Integer
						.valueOf(datarecoverform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Recover> list = interfaceforresultsettolist
				.ViewOc_Data_Recover(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("datarecoverform", datarecoverform);
		System.out.println("list.size()" + list.size());

		return mapping.findForward("success");
	}

	public ActionForward admin_search_import_recover(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataRecoverForm datarecoverform = (DataRecoverForm) form;
		String sql = "select * from OC_XLS_UPLOAD order by id DESC";
		System.out.println("SQL=" + sql);
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(datarecoverform.getRowcountperpage()), Integer
						.valueOf(datarecoverform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Recover> list = interfaceforresultsettolist
				.ViewOc_Data_Recover(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("datarecoverform", datarecoverform);
		System.out.println("list.size()" + list.size());

		return mapping.findForward("success");
	}

	public ActionForward admin_insert_import_recover(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataRecoverForm datarecoverform = (DataRecoverForm) form;
		String id = datarecoverform.getId();
		System.out.println("ID=" + id);
		List<Oc_Xls_Upload> oc_xls_upload = this.service_admin
				.Find_Oc_Xls_Upload(id);
		Oc_Xls_Upload e = oc_xls_upload.get(0);
		if (e.getDate_num().equals("海洋环境")) {
			this.service_admin.Delete_Oc_Data_Sur_By_Xls(id);// 删除该批次号中的数据
			System.out.println("开始读取数据，导入工序");

			// 开始读取数据，导入工序
			// 读取所有的站点，放入内存。
			// 读取所有的属性，放入内存。
			// 开始读取行。
			// 分析行的前几列，并在站点表中比对，如果存在则通过 不存在则放弃。
			//
			EnitityBeanOc_Voyage enititybeanoc_voyage = new EnitityBeanOc_Voyage();// 校验用实例名
			EntityBeanOc_Depthlist oc_depthlist = new EntityBeanOc_Depthlist();// 校验用实例名
			EntityBeanOc_Station oc_station = new EntityBeanOc_Station();// 校验用实例名
			EntityBean_Oc_Property_Tools oc_property_tools = new EntityBean_Oc_Property_Tools();// 检查时的赋值对象
			EntityBean_Oc_Property oc_property = new EntityBean_Oc_Property();// 检查时的赋值对象
			Double valuekey;// 检查时的赋值对象
			List<EnitityBeanOc_Voyage> voyagelist = this.service_admin
					.Find_Oc_Voyage_By_boatid(Integer.valueOf(e.getBoat_id()));// 按照科考船读取数据

			System.out.println("根据科考船的数据获得了航次的大小=" + voyagelist.size());
			List<EntityBeanOc_Depthlist> depthlist = this.service_admin
					.Find_Oc_Depthlist();

			System.out.println("根据科考船的数据获得了层深的大小=" + depthlist.size());
			List<EntityBeanOc_Station> stationlist = new ArrayList<EntityBeanOc_Station>();

			stationlist = this.service_admin.Find_Oc_Station_is_active();// 获取了所有的有效站点
			System.out.println("获取了所有的有效站点的大小=" + stationlist.size());
			List<EntityBean_Oc_Property> propertylist = this.service_admin
					.Find_EntityBean_Oc_Property_by_property_kind(5);
			List<String> propertyliststr = new ArrayList<String>();
			List<EntityBean_Oc_Property> propertylist_table = new ArrayList<EntityBean_Oc_Property>();// 记录在本表中使用到的属性值
			for (int i = 0; i < propertylist.size(); i++) {
				propertyliststr.add(propertylist.get(i).getProperty_name());
				System.out.println(propertylist.get(i).getProperty_name());
			}

			System.out.println("根据科考船的数据获得了属性的大小=" + propertylist.size());
			List<EntityBean_Oc_Property_Tools> propertytoolslist = this.service_admin
					.Find_EntityBean_Oc_Property_Tools_Is_Active();

			/*
			 * List<String>propertytoolsliststr=new ArrayList<String>(); for(int
			 * i=0;i<propertytoolslist.size();i++) {
			 * propertytoolsliststr.add(propertytoolslist
			 * .get(i).getTools_name());
			 * System.out.println(propertytoolslist.get(i).getTools_name()); }
			 */
			/*
			 * System.out .println("根据科考船的数据获得了属性工具的大小=" +
			 * propertytoolslist.size());
			 */
			Workbook workBook = null;
			InputStream is = new FileInputStream(e.getFile_path());// 读取上传的xls文件
			workBook = Workbook.getWorkbook(is);
			// 从0开始，第一张工作表
			Sheet sheet = workBook.getSheet(0);
			int row = sheet.getRows();
			int column = sheet.getColumns();
			if (column < 7) {
				System.out.println("表格宽度有问题,怀疑文件格式错误");
				return null;
			}
			System.out.println("row=" + row);
			System.out.println("column=" + column);
			System.out.println("检查表头宽度");
			// 航次 站位 经度(E) 纬度(N) 采样时间(年-月-日-时:分) 深度（m） 层（m） 压强(db) 温度(deg C)
			// 盐度(PSU)
			// 潜在温度(deg C) 潜在密度(Kg/m^3) 溶解氧(μM) 硝酸盐(μM) 磷酸盐(μM) 硅酸盐(μM)
			// 氨盐(μM) 亚硝酸盐(μM) 初级生产力(mgC﹒m-3h-1) δ18O(‰) 备注
			List<String> liststr = new ArrayList<String>();
			liststr.add("航次");
			liststr.add("站位");
			liststr.add("经度(E)");
			liststr.add("纬度(N)");
			liststr.add("采样时间(年-月-日-时:分)");
			liststr.add("深度(m)");
			liststr.add("层(m)");
			for (int i = 0; i < 7; i++) {
				Cell cell = sheet.getCell(i, 0);
				if (!cell.getContents().toString().equals(liststr.get(i))) {
					System.out.println("表头数据有错误,期待的值=" + liststr.get(i));
					return null;// 返回错误的页面并告知错误
				}
			}
			for (int i = 7; i < column - 1; i++) {
				Cell cell = sheet.getCell(i, 0);
				String cellstr = cell.getContents().toString();
				Integer kh = cellstr.indexOf("(");
				cellstr = cellstr.substring(0, kh);
				System.out.println("cellstr=" + cellstr);
				if (!propertyliststr.contains(cellstr)) {
					System.out.println("系统中没有这个有效参数,查看有无 " + cellstr + " 属性");
					return null;
				} else {
					// 在propertylist_table增加相应的数据
					EntityBean_Oc_Property property_table = new EntityBean_Oc_Property();
					for (int ck_cellstr = 0; ck_cellstr < propertylist.size(); ck_cellstr++) {
						if (cellstr.equals(propertylist.get(ck_cellstr)
								.getProperty_name())) {
							property_table = propertylist.get(ck_cellstr);
							propertylist_table.add(property_table);
						}
					}
				}
			}
			System.out.println("在导入的XLS文件中,使用的属性大小="
					+ propertylist_table.size());
			Cell cell = sheet.getCell(column - 1, 0);
			String cellstr = cell.getContents().toString();

			if (!cellstr.equals("备注")) {
				System.out.println("最后一列不是备注列,期待的值=备注");
				return null;
			}
			System.out.println("表格头部校验完成,开始校验表格数据");
			// 忽略了英文的标题，从第三列开始读取数据
			List<EnitityBeanOc_Date_Sur> Date_list = new ArrayList<EnitityBeanOc_Date_Sur>();// 生成一个需要最后写入到数据库的字段
			for (int i = 2; i < row; i++) {
				EnitityBeanOc_Date_Sur e0 = new EnitityBeanOc_Date_Sur();
				// 校验航次
				cell = sheet.getCell(0, i);
				String voyagename = cell.getContents().toString();
				String find_voyage = "not";
				for (int voyage_id = 0; voyage_id < voyagelist.size(); voyage_id++) {
					if (voyagelist.get(voyage_id).getVoyage_name().equals(
							voyagename)) {
						enititybeanoc_voyage = voyagelist.get(voyage_id);
						find_voyage = "yes";
						break;
					}
				}
				if (find_voyage.equals("yes")) {
					System.out.println("航次校验通过,航次名称="
							+ enititybeanoc_voyage.getVoyage_name());
					e0.setOc_voyage_id(enititybeanoc_voyage.getId());// 设置了一个航次数据
				} else {
					System.out.println("未能发现正确的航次名称,期待的值=" + voyagename);
					return null;
				}
				// 航次校验完成，开始校验站点
				EntityBeanOc_Station e_station = new EntityBeanOc_Station();
				cell = sheet.getCell(1, i);
				e_station.setStation_name(cell.getContents());
				cell = sheet.getCell(2, i);
				e_station.setLongitude(cell.getContents());
				cell = sheet.getCell(3, i);
				e_station.setDimensionality(cell.getContents());
				cell = sheet.getCell(5, i);
				e_station.setDepth(Double.valueOf(cell.getContents()));
				String find_station = "not";
				for (int find_station_id = 0; find_station_id < stationlist
						.size(); find_station_id++) {
					/*
					 * System.out.println("站点名称="+stationlist.get(find_station_id
					 * ).getStation_name());
					 * System.out.println("站点深度="+stationlist
					 * .get(find_station_id).getDepth());
					 * System.out.println("站点经度="
					 * +stationlist.get(find_station_id).getDimensionality());
					 * System
					 * .out.println("站点维度="+stationlist.get(find_station_id
					 * ).getLongitude());
					 * 
					 * 
					 * 
					 * System.out.println("比较站点名称="+e_station.getStation_name());
					 * System.out.println("比较站点深度="+e_station.getDepth());
					 * System
					 * .out.println("比较站点经度="+e_station.getDimensionality());
					 * System.out.println("比较站点维度="+e_station.getLongitude());
					 */
					if (stationlist.get(find_station_id).getStation_name()
							.equals(e_station.getStation_name())
							&& stationlist.get(find_station_id).getDepth() == e_station
									.getDepth()
							&& stationlist.get(find_station_id)
									.getDimensionality().equals(
											e_station.getDimensionality())
							&& stationlist.get(find_station_id).getLongitude()
									.equals(e_station.getLongitude())
							&& stationlist.get(find_station_id)
									.getOc_voyage_id().equals(
											e0.getOc_voyage_id())) {
						find_station = "yes";
						e_station = stationlist.get(find_station_id);
						e0.setOc_station_id(e_station.getId());// 设置了站点值
						break;
					}
				}
				if (find_station.equals("yes")) {
					System.out.println("站点校验通过,站点名称="
							+ e_station.getStation_name());
				} else {
					System.out.println("未能发现正确的站点名称,期待的值="
							+ e_station.getStation_name());
					return null;
				}// 站点校验完成
				cell = sheet.getCell(6, i);
				EntityBeanOc_Depthlist entityBeanoc_depthlist = new EntityBeanOc_Depthlist();
				entityBeanoc_depthlist.setDepth(Integer.valueOf(cell
						.getContents()));
				String find_depthlist = "not";
				for (int deplist_id = 0; deplist_id < depthlist.size(); deplist_id++) {
					if (entityBeanoc_depthlist.getDepth().equals(
							depthlist.get(deplist_id).getDepth())) {
						find_depthlist = "yes";
						entityBeanoc_depthlist = depthlist.get(deplist_id);
						break;
					}
				}
				if (find_depthlist.equals("yes")) {
					System.out.println("层深 校验通过,层深 名称="
							+ entityBeanoc_depthlist.getDepth());
					e0.setOc_deplist_id(entityBeanoc_depthlist.getId());// 设置了一个深度数据
				} else {
					System.out.println("层深 校验通过,层深 名称="
							+ entityBeanoc_depthlist.getDepth());
					return null;
				}// 层深校验完成

				for (int property_id = 7; property_id < column - 1; property_id++) {
					cell = sheet.getCell(property_id, i);
					String cellproperty = cell.getContents();
					Integer kh_1 = cellproperty.indexOf("(");
					Integer kh_2 = cellproperty.indexOf(")");
					if (kh_1 == -1 || kh_2 == -1) {
						System.out.println("属性值中缺少工具内容");
						return null;
					}
					valuekey = Double.valueOf(cellproperty.substring(0, kh_1));
					String property_tool = cellproperty.substring(kh_1 + 1,
							kh_2);
					// System.out.println("属性的值="+valuekey);
					// System.out.println("属性工具名称="+property_tool);
					oc_property = propertylist_table.get(property_id - 7);
					Integer pid = propertylist_table.get(property_id - 7)
							.getId();
					// System.out.println("属性的PID="+pid);
					String find_property_tools = "not";
					for (int ch_property_tool_id = 0; ch_property_tool_id < propertytoolslist
							.size(); ch_property_tool_id++) {
						// System.out.println(propertytoolslist.get(ch_property_tool_id).getTools_name());
						// System.out.println(propertytoolslist.get(ch_property_tool_id).getPid());
						if (propertytoolslist.get(ch_property_tool_id).getPid()
								.equals(pid)
								&& propertytoolslist.get(ch_property_tool_id)
										.getTools_name().equals(property_tool)) {
							find_property_tools = "yes";
							oc_property_tools = propertytoolslist
									.get(ch_property_tool_id);
							break;
						}
					}
					if (find_property_tools.equals("yes")) {
						EnitityBeanOc_Date_Sur Oc_Date_Sur = new EnitityBeanOc_Date_Sur();
						Oc_Date_Sur.setDel("OFF");
						Oc_Date_Sur.setOc_deplist_id(e0.getOc_deplist_id());
						Oc_Date_Sur.setOc_voyage_id(e0.getOc_voyage_id());
						Oc_Date_Sur.setOc_station_id(e0.getOc_station_id());
						Oc_Date_Sur.setOc_property_id(oc_property.getId());
						Oc_Date_Sur.setOc_property_tools_id(oc_property_tools
								.getId());
						Oc_Date_Sur.setValue_key(valuekey);
						Oc_Date_Sur.setOc_xls_upload(0);
						System.out.println("为录入的表单增加了一个数据"
								+ Oc_Date_Sur.Read_Me());
						Date_list.add(Oc_Date_Sur);
					} else {
						System.out.println("未能发现合适的属性测量工具,期待的值="
								+ property_tool);
						return null;
					}

				}

			}

			System.out.println("数据分析结束,开始记录到数据库中...");

			System.out.println("需要录入的数据为=" + Date_list.size());
			EntityBeanL_Sequence L_DATE = this.service_public
					.Find_L_Sequence_By_seq_Name("SEQ_OC_DATE_SUR");
			Integer id_date = L_DATE.getSeq_Value() + 1;
			for (int install = 0; install < Date_list.size(); install++) {
				Date_list.get(install).setOc_xls_upload(e.getId());
				Date_list.get(install).setId(id_date);

				id_date = id_date + 1;
				this.service_admin.Insert_Oc_Data_Sur(Date_list.get(install));
			}
			L_DATE.setSeq_Value(id_date);
			this.service_public.Update_L_Sequence(L_DATE);

		} else if (e.getDate_num().equals("底栖环境")) {
			this.service_admin.Delete_Oc_Data_Ben_By_Xls(e.getId().toString());
			System.out.println("开始读取数据，导入工序");

			// 开始读取数据，导入工序
			// 读取所有的站点，放入内存。
			// 读取所有的属性，放入内存。
			// 开始读取行。
			// 分析行的前几列，并在站点表中比对，如果存在则通过 不存在则放弃。
			//
			EnitityBeanOc_Voyage_Ben enititybeanoc_voyage_ben = new EnitityBeanOc_Voyage_Ben();// 校验用实例名
			EntityBeanOc_Depthlist_Ben oc_depthlist_ben = new EntityBeanOc_Depthlist_Ben();// 校验用实例名
			EntityBeanOc_Station_Ben oc_station_ben = new EntityBeanOc_Station_Ben();// 校验用实例名
			EntityBean_Oc_Property_Tools_Ben oc_property_tools_ben = new EntityBean_Oc_Property_Tools_Ben();// 检查时的赋值对象
			EntityBean_Oc_Property_Ben oc_property_ben = new EntityBean_Oc_Property_Ben();// 检查时的赋值对象
			Double valuekey;// 检查时的赋值对象
			List<EnitityBeanOc_Voyage_Ben> voyagelist_ben = this.service_admin
					.Find_Oc_Voyage_Ben_By_boatid(Integer.valueOf(e
							.getBoat_id()));// 按照科考船读取数据

			System.out.println("根据科考船的数据获得了航次的大小=" + voyagelist_ben.size());
			List<EntityBeanOc_Depthlist_Ben> depthlist_ben = this.service_admin
					.Find_Oc_Depthlist_Ben();

			System.out.println("根据科考船的数据获得了层深的大小=" + depthlist_ben.size());
			List<EntityBeanOc_Station_Ben> stationlist_ben = new ArrayList<EntityBeanOc_Station_Ben>();

			stationlist_ben = this.service_admin
					.Find_Oc_Station_Ben_is_active();// 获取了所有的有效站点
			System.out.println("获取了所有的有效站点的大小=" + stationlist_ben.size());

			List<EntityBean_Oc_Property_Ben> propertylist_ben = this.service_admin
					.Find_EntityBean_Oc_Property_Ben_by_property_kind(8);
			List<String> propertylist_ben_str = new ArrayList<String>();
			List<EntityBean_Oc_Property_Ben> propertylist_table_ben = new ArrayList<EntityBean_Oc_Property_Ben>();// 记录在本表中使用到的属性值
			for (int i = 0; i < propertylist_ben.size(); i++) {
				propertylist_ben_str.add(propertylist_ben.get(i)
						.getProperty_name());
				System.out.println(propertylist_ben.get(i).getProperty_name());
			}

			System.out.println("根据科考船的数据获得了属性的大小=" + propertylist_ben.size());
			List<EntityBean_Oc_Property_Tools_Ben> propertytoolslist_ben = this.service_admin
					.Find_EntityBean_Oc_Property_Tools_Ben_Is_Active();

			/*
			 * List<String>propertytoolsliststr=new ArrayList<String>(); for(int
			 * i=0;i<propertytoolslist.size();i++) {
			 * propertytoolsliststr.add(propertytoolslist
			 * .get(i).getTools_name());
			 * System.out.println(propertytoolslist.get(i).getTools_name()); }
			 */
			System.out.println("根据科考船的数据获得了属性工具的大小="
					+ propertytoolslist_ben.size());
			Workbook workBook = null;
			InputStream is = new FileInputStream(e.getFile_path());// 读取上传的xls文件
			workBook = Workbook.getWorkbook(is);
			// 从0开始，第一张工作表
			Sheet sheet = workBook.getSheet(0);
			int row = sheet.getRows();
			int column = sheet.getColumns();
			if (column < 7) {
				System.out.println("表格宽度有问题,怀疑文件格式错误");
				return null;
			}
			System.out.println("row=" + row);
			System.out.println("column=" + column);
			System.out.println("检查表头宽度");
			// 航次 站位 经度(E) 纬度(N) 采样时间(年-月-日-时:分) 深度（m） 层（m） 压强(db) 温度(deg C)
			// 盐度(PSU)
			// 潜在温度(deg C) 潜在密度(Kg/m^3) 溶解氧(μM) 硝酸盐(μM) 磷酸盐(μM) 硅酸盐(μM)
			// 氨盐(μM) 亚硝酸盐(μM) 初级生产力(mgC﹒m-3h-1) δ18O(‰) 备注
			List<String> liststr = new ArrayList<String>();
			liststr.add("航次");
			liststr.add("站位");
			liststr.add("经度(E)");
			liststr.add("纬度(N)");
			liststr.add("采样时间(年-月-日-时:分)");
			liststr.add("深度(m)");
			liststr.add("层(m)");
			for (int i = 0; i < 7; i++) {
				Cell cell = sheet.getCell(i, 0);
				if (!cell.getContents().toString().equals(liststr.get(i))) {
					System.out.println("表头数据有错误,期待的值=" + liststr.get(i));
					return null;// 返回错误的页面并告知错误
				}
			}
			for (int i = 7; i < column - 1; i++) {
				Cell cell = sheet.getCell(i, 0);
				String cellstr = cell.getContents().toString();
				Integer kh = cellstr.indexOf("(");
				cellstr = cellstr.substring(0, kh);
				System.out.println("cellstr=" + cellstr);
				if (!propertylist_ben_str.contains(cellstr)) {
					System.out.println("系统中没有这个有效参数,查看有无 " + cellstr + " 属性");
					return null;
				} else {
					// 在propertylist_table增加相应的数据
					EntityBean_Oc_Property_Ben property_table_ben = new EntityBean_Oc_Property_Ben();
					for (int ck_cellstr = 0; ck_cellstr < propertylist_ben
							.size(); ck_cellstr++) {
						if (cellstr.equals(propertylist_ben.get(ck_cellstr)
								.getProperty_name())) {
							property_table_ben = propertylist_ben
									.get(ck_cellstr);
							propertylist_table_ben.add(property_table_ben);
						}
					}
				}
			}
			System.out.println("在导入的XLS文件中,使用的属性大小="
					+ propertylist_table_ben.size());
			Cell cell = sheet.getCell(column - 1, 0);
			String cellstr = cell.getContents().toString();

			if (!cellstr.equals("备注")) {
				System.out.println("最后一列不是备注列,期待的值=备注");
				return null;
			}
			System.out.println("表格头部校验完成,开始校验表格数据");
			// 忽略了英文的标题，从第三列开始读取数据
			List<EnitityBeanOc_Date_Ben> Date_list = new ArrayList<EnitityBeanOc_Date_Ben>();// 生成一个需要最后写入到数据库的字段
			for (int i = 2; i < row; i++) {
				EnitityBeanOc_Date_Ben e0 = new EnitityBeanOc_Date_Ben();
				// 校验航次
				cell = sheet.getCell(0, i);
				String voyagename = cell.getContents().toString();
				String find_voyage = "not";
				for (int voyage_id = 0; voyage_id < voyagelist_ben.size(); voyage_id++) {
					if (voyagelist_ben.get(voyage_id).getVoyage_name().equals(
							voyagename)) {
						enititybeanoc_voyage_ben = voyagelist_ben
								.get(voyage_id);
						find_voyage = "yes";
						break;
					}
				}
				if (find_voyage.equals("yes")) {
					System.out.println("航次校验通过,航次名称="
							+ enititybeanoc_voyage_ben.getVoyage_name());
					e0.setOc_voyage_id(enititybeanoc_voyage_ben.getId());// 设置了一个航次数据
				} else {
					System.out.println("未能发现正确的航次名称,期待的值=" + voyagename);
					return null;
				}
				// 航次校验完成，开始校验站点
				EntityBeanOc_Station_Ben e_station = new EntityBeanOc_Station_Ben();
				cell = sheet.getCell(1, i);
				e_station.setStation_name(cell.getContents());
				cell = sheet.getCell(2, i);
				e_station.setLongitude(cell.getContents());
				cell = sheet.getCell(3, i);
				e_station.setDimensionality(cell.getContents());
				cell = sheet.getCell(5, i);
				e_station.setDepth(Double.valueOf(cell.getContents()));
				String find_station = "not";
				for (int find_station_id = 0; find_station_id < stationlist_ben
						.size(); find_station_id++) {
					/*
					 * System.out.println("站点名称="+stationlist.get(find_station_id
					 * ).getStation_name());
					 * System.out.println("站点深度="+stationlist
					 * .get(find_station_id).getDepth());
					 * System.out.println("站点经度="
					 * +stationlist.get(find_station_id).getDimensionality());
					 * System
					 * .out.println("站点维度="+stationlist.get(find_station_id
					 * ).getLongitude());
					 * 
					 * 
					 * System.out.println("比较站点名称="+e_station.getStation_name());
					 * System.out.println("比较站点深度="+e_station.getDepth());
					 * System
					 * .out.println("比较站点经度="+e_station.getDimensionality());
					 * System.out.println("比较站点维度="+e_station.getLongitude());
					 */
					if (stationlist_ben.get(find_station_id).getStation_name()
							.equals(e_station.getStation_name())
							&& stationlist_ben.get(find_station_id).getDepth() == e_station
									.getDepth()
							&& stationlist_ben.get(find_station_id)
									.getDimensionality().equals(
											e_station.getDimensionality())
							&& stationlist_ben.get(find_station_id)
									.getLongitude().equals(
											e_station.getLongitude())
							&& stationlist_ben.get(find_station_id)
									.getOc_voyage_id().equals(
											e0.getOc_voyage_id())) {
						find_station = "yes";
						e_station = stationlist_ben.get(find_station_id);
						e0.setOc_station_id(e_station.getId());// 设置了站点值
						break;
					}
				}
				if (find_station.equals("yes")) {
					System.out.println("站点校验通过,站点名称="
							+ e_station.getStation_name());
				} else {
					System.out.println("未能发现正确的站点名称,期待的值="
							+ e_station.getStation_name());
					return null;
				}// 站点校验完成
				cell = sheet.getCell(6, i);
				EntityBeanOc_Depthlist_Ben entityBeanoc_depthlist_ben = new EntityBeanOc_Depthlist_Ben();
				entityBeanoc_depthlist_ben.setDepth(Integer.valueOf(cell
						.getContents()));
				String find_depthlist = "not";
				for (int deplist_id = 0; deplist_id < depthlist_ben.size(); deplist_id++) {
					if (entityBeanoc_depthlist_ben.getDepth().equals(
							depthlist_ben.get(deplist_id).getDepth())) {
						find_depthlist = "yes";
						entityBeanoc_depthlist_ben = depthlist_ben
								.get(deplist_id);
						break;
					}
				}
				if (find_depthlist.equals("yes")) {
					System.out.println("层深 校验通过,层深 名称="
							+ entityBeanoc_depthlist_ben.getDepth());
					e0.setOc_deplist_id(entityBeanoc_depthlist_ben.getId());// 设置了一个深度数据
				} else {
					System.out.println("未能通过层深 校验通过,层深 名称="
							+ entityBeanoc_depthlist_ben.getDepth());
					return null;
				}// 层深校验完成

				for (int property_id = 7; property_id < column - 1; property_id++) {
					cell = sheet.getCell(property_id, i);
					String cellproperty = cell.getContents();
					Integer kh_1 = cellproperty.indexOf("(");
					Integer kh_2 = cellproperty.indexOf(")");
					if (kh_1 == -1 || kh_2 == -1) {
						System.out.println("属性值中缺少工具内容");
						return null;
					}
					valuekey = Double.valueOf(cellproperty.substring(0, kh_1));
					String property_tool = cellproperty.substring(kh_1 + 1,
							kh_2);
					// System.out.println("属性的值="+valuekey);
					// System.out.println("属性工具名称="+property_tool);
					oc_property_ben = propertylist_table_ben
							.get(property_id - 7);
					Integer pid = propertylist_table_ben.get(property_id - 7)
							.getId();
					// System.out.println("属性的PID="+pid);
					String find_property_tools = "not";
					for (int ch_property_tool_id = 0; ch_property_tool_id < propertytoolslist_ben
							.size(); ch_property_tool_id++) {
						// System.out.println(propertytoolslist.get(ch_property_tool_id).getTools_name());
						// System.out.println(propertytoolslist.get(ch_property_tool_id).getPid());
						if (propertytoolslist_ben.get(ch_property_tool_id)
								.getPid().equals(pid)
								&& propertytoolslist_ben.get(
										ch_property_tool_id).getTools_name()
										.equals(property_tool)) {
							find_property_tools = "yes";
							oc_property_tools_ben = propertytoolslist_ben
									.get(ch_property_tool_id);
							break;
						}
					}
					if (find_property_tools.equals("yes")) {
						EnitityBeanOc_Date_Ben Oc_Date_Ben = new EnitityBeanOc_Date_Ben();
						Oc_Date_Ben.setDel("OFF");
						Oc_Date_Ben.setOc_deplist_id(e0.getOc_deplist_id());
						Oc_Date_Ben.setOc_voyage_id(e0.getOc_voyage_id());
						Oc_Date_Ben.setOc_station_id(e0.getOc_station_id());
						Oc_Date_Ben.setOc_property_id(oc_property_ben.getId());
						Oc_Date_Ben
								.setOc_property_tools_id(oc_property_tools_ben
										.getId());
						Oc_Date_Ben.setValue_key(valuekey);
						Oc_Date_Ben.setOc_xls_upload(0);
						System.out.println("为录入的表单增加了一个数据"
								+ Oc_Date_Ben.Read_Me());
						Date_list.add(Oc_Date_Ben);
					} else {
						System.out.println("未能发现合适的属性测量工具,期待的值="
								+ property_tool);
						return null;
					}

				}

				// 按照条件搜索站点名称 找到为有效 没找到就是无效

			}

			System.out.println("数据分析结束,开始记录到数据库中...");

			System.out.println("需要录入的数据为=" + Date_list.size());
			EntityBeanL_Sequence L_DATE = this.service_public
					.Find_L_Sequence_By_seq_Name("SEQ_OC_DATE_BEN");
			Integer id_date = L_DATE.getSeq_Value() + 1;
			for (int install = 0; install < Date_list.size(); install++) {
				Date_list.get(install).setOc_xls_upload(e.getId());
				Date_list.get(install).setId(id_date);

				id_date = id_date + 1;
				this.service_admin.Insert_Oc_Data_Ben(Date_list.get(install));
			}
			L_DATE.setSeq_Value(id_date);
			this.service_public.Update_L_Sequence(L_DATE);

		} else if (e.getDate_num().equals("海冰生态")) {
			this.service_admin.Delete_Oc_Data_Ice_By_Xls(e.getId().toString());

			System.out.println("开始读取数据，导入工序");

			// 开始读取数据，导入工序
			// 读取所有的站点，放入内存。
			// 读取所有的属性，放入内存。
			// 开始读取行。
			// 分析行的前几列，并在站点表中比对，如果存在则通过 不存在则放弃。
			//
			EnitityBeanOc_Voyage_Ice enititybeanoc_voyage_ice = new EnitityBeanOc_Voyage_Ice();// 校验用实例名
			EntityBeanOc_Depthlist_Ice oc_depthlist_ice = new EntityBeanOc_Depthlist_Ice();// 校验用实例名
			EntityBeanOc_Station_Ice oc_station_ice = new EntityBeanOc_Station_Ice();// 校验用实例名
			EntityBean_Oc_Property_Tools_Ice oc_property_tools_ice = new EntityBean_Oc_Property_Tools_Ice();// 检查时的赋值对象
			EntityBean_Oc_Property_Ice oc_property_ice = new EntityBean_Oc_Property_Ice();// 检查时的赋值对象
			Double valuekey;// 检查时的赋值对象
			List<EnitityBeanOc_Voyage_Ice> voyagelist_ice = this.service_admin
					.Find_Oc_Voyage_Ice_By_boatid(Integer.valueOf(e
							.getBoat_id()));// 按照科考船读取数据

			System.out.println("根据科考船的数据获得了航次的大小=" + voyagelist_ice.size());
			List<EntityBeanOc_Depthlist_Ice> depthlist_ice = this.service_admin
					.Find_EntityBeanOc_Depthlist_Ice();

			System.out.println("根据科考船的数据获得了层深的大小=" + depthlist_ice.size());
			List<EntityBeanOc_Station_Ice> stationlist_ice = new ArrayList<EntityBeanOc_Station_Ice>();

			stationlist_ice = this.service_admin
					.Find_Oc_Station_Ice_is_active();// 获取了所有的有效站点
			System.out.println("获取了所有的有效站点的大小=" + stationlist_ice.size());
			List<EntityBean_Oc_Property_Ice> propertylist = this.service_admin
					.Find_EntityBean_Oc_Property_Ice_by_property_kind(6);
			List<String> propertyliststr = new ArrayList<String>();
			List<EntityBean_Oc_Property_Ice> propertylist_table = new ArrayList<EntityBean_Oc_Property_Ice>();// 记录在本表中使用到的属性值
			for (int i = 0; i < propertylist.size(); i++) {
				propertyliststr.add(propertylist.get(i).getProperty_name());
				System.out.println(propertylist.get(i).getProperty_name());
			}
			System.out.println("根据科考船的数据获得了属性的大小=" + propertylist.size());
			List<EntityBean_Oc_Property_Tools_Ice> propertytoolslist = this.service_admin
					.Find_EntityBean_Oc_Property_Tools_Ice_Is_Active();

			/*
			 * List<String>propertytoolsliststr=new ArrayList<String>(); for(int
			 * i=0;i<propertytoolslist.size();i++) {
			 * propertytoolsliststr.add(propertytoolslist
			 * .get(i).getTools_name());
			 * System.out.println(propertytoolslist.get(i).getTools_name()); }
			 */
			System.out
					.println("根据科考船的数据获得了属性工具的大小=" + propertytoolslist.size());
			Workbook workBook = null;
			InputStream is = new FileInputStream(e.getFile_path());// 读取上传的xls文件
			workBook = Workbook.getWorkbook(is);
			// 从0开始，第一张工作表
			Sheet sheet = workBook.getSheet(0);
			int row = sheet.getRows();
			int column = sheet.getColumns();
			if (column < 7) {
				System.out.println("表格宽度有问题,怀疑文件格式错误");
				return null;
			}
			System.out.println("row=" + row);
			System.out.println("column=" + column);
			System.out.println("检查表头宽度");
			// 航次 站位 经度(E) 纬度(N) 采样时间(年-月-日-时:分) 深度（m） 层（m） 压强(db) 温度(deg C)
			// 盐度(PSU)
			// 潜在温度(deg C) 潜在密度(Kg/m^3) 溶解氧(μM) 硝酸盐(μM) 磷酸盐(μM) 硅酸盐(μM)
			// 氨盐(μM) 亚硝酸盐(μM) 初级生产力(mgC﹒m-3h-1) δ18O(‰) 备注
			List<String> liststr = new ArrayList<String>();
			liststr.add("航次");
			liststr.add("站位");
			liststr.add("经度(E)");
			liststr.add("纬度(N)");
			liststr.add("采样时间(年-月-日-时:分)");
			liststr.add("深度(m)");
			liststr.add("层(m)");
			for (int i = 0; i < 7; i++) {
				Cell cell = sheet.getCell(i, 0);
				if (!cell.getContents().toString().equals(liststr.get(i))) {
					System.out.println("表头数据有错误,期待的值=" + liststr.get(i));
					return null;// 返回错误的页面并告知错误
				}
			}
			for (int i = 7; i < column - 1; i++) {
				Cell cell = sheet.getCell(i, 0);
				String cellstr = cell.getContents().toString();
				Integer kh = cellstr.indexOf("(");
				cellstr = cellstr.substring(0, kh);
				System.out.println("cellstr=" + cellstr);
				if (!propertyliststr.contains(cellstr)) {
					System.out.println("系统中没有这个有效参数,查看有无 " + cellstr + " 属性");
					return null;
				} else {
					// 在propertylist_table增加相应的数据
					EntityBean_Oc_Property_Ice property_table = new EntityBean_Oc_Property_Ice();
					for (int ck_cellstr = 0; ck_cellstr < propertylist.size(); ck_cellstr++) {
						if (cellstr.equals(propertylist.get(ck_cellstr)
								.getProperty_name())) {
							property_table = propertylist.get(ck_cellstr);
							propertylist_table.add(property_table);
						}
					}
				}
			}
			System.out.println("在导入的XLS文件中,使用的属性大小="
					+ propertylist_table.size());
			Cell cell = sheet.getCell(column - 1, 0);
			String cellstr = cell.getContents().toString();

			if (!cellstr.equals("备注")) {
				System.out.println("最后一列不是备注列,期待的值=备注");
				return null;
			}
			System.out.println("表格头部校验完成,开始校验表格数据");
			// 忽略了英文的标题，从第三列开始读取数据
			List<EnitityBeanOc_Date_Ice> Date_list = new ArrayList<EnitityBeanOc_Date_Ice>();// 生成一个需要最后写入到数据库的字段
			for (int i = 2; i < row; i++) {
				EnitityBeanOc_Date_Ice e0 = new EnitityBeanOc_Date_Ice();
				// 校验航次
				cell = sheet.getCell(0, i);
				String voyagename = cell.getContents().toString();
				String find_voyage = "not";
				for (int voyage_id = 0; voyage_id < voyagelist_ice.size(); voyage_id++) {
					if (voyagelist_ice.get(voyage_id).getVoyage_name().equals(
							voyagename)) {
						enititybeanoc_voyage_ice = voyagelist_ice
								.get(voyage_id);
						find_voyage = "yes";
						break;
					}
				}
				if (find_voyage.equals("yes")) {
					System.out.println("航次校验通过,航次名称="
							+ enititybeanoc_voyage_ice.getVoyage_name());
					e0.setOc_voyage_id(enititybeanoc_voyage_ice.getId());// 设置了一个航次数据
				} else {
					System.out.println("未能发现正确的航次名称,期待的值=" + voyagename);
					return null;
				}
				// 航次校验完成，开始校验站点
				EntityBeanOc_Station_Ice e_station_ice = new EntityBeanOc_Station_Ice();
				cell = sheet.getCell(1, i);
				e_station_ice.setStation_name(cell.getContents());
				cell = sheet.getCell(2, i);
				e_station_ice.setLongitude(cell.getContents());
				cell = sheet.getCell(3, i);
				e_station_ice.setDimensionality(cell.getContents());
				cell = sheet.getCell(5, i);
				e_station_ice.setDepth(Double.valueOf(cell.getContents()));
				String find_station = "not";
				for (int find_station_id = 0; find_station_id < stationlist_ice
						.size(); find_station_id++) {
					System.out.println("站点名称="
							+ stationlist_ice.get(find_station_id)
									.getStation_name());
					System.out.println("站点深度="
							+ stationlist_ice.get(find_station_id).getDepth());
					System.out.println("站点经度="
							+ stationlist_ice.get(find_station_id)
									.getDimensionality());
					System.out.println("站点维度="
							+ stationlist_ice.get(find_station_id)
									.getLongitude());

					System.out.println("比较站点名称="
							+ e_station_ice.getStation_name());
					System.out.println("比较站点深度=" + e_station_ice.getDepth());
					System.out.println("比较站点经度="
							+ e_station_ice.getDimensionality());
					System.out
							.println("比较站点维度=" + e_station_ice.getLongitude());

					if (stationlist_ice.get(find_station_id).getStation_name()
							.equals(e_station_ice.getStation_name())
							&& stationlist_ice.get(find_station_id).getDepth() == e_station_ice
									.getDepth()
							&& stationlist_ice.get(find_station_id)
									.getDimensionality().equals(
											e_station_ice.getDimensionality())
							&& stationlist_ice.get(find_station_id)
									.getLongitude().equals(
											e_station_ice.getLongitude())
							&& stationlist_ice.get(find_station_id)
									.getOc_voyage_id().equals(
											e0.getOc_voyage_id())) {
						find_station = "yes";
						e_station_ice = stationlist_ice.get(find_station_id);
						e0.setOc_station_id(e_station_ice.getId());// 设置了站点值
						break;
					}
				}
				if (find_station.equals("yes")) {
					System.out.println("站点校验通过,站点名称="
							+ e_station_ice.getStation_name());
				} else {
					System.out.println("未能发现正确的站点名称,期待的值="
							+ e_station_ice.getStation_name());
					return null;
				}// 站点校验完成
				cell = sheet.getCell(6, i);
				EntityBeanOc_Depthlist_Ice entityBeanoc_depthlist = new EntityBeanOc_Depthlist_Ice();
				entityBeanoc_depthlist.setDepth(Integer.valueOf(cell
						.getContents()));
				String find_depthlist = "not";
				for (int deplist_id = 0; deplist_id < depthlist_ice.size(); deplist_id++) {
					if (entityBeanoc_depthlist.getDepth().equals(
							depthlist_ice.get(deplist_id).getDepth())) {
						find_depthlist = "yes";
						entityBeanoc_depthlist = depthlist_ice.get(deplist_id);
						break;
					}
				}
				if (find_depthlist.equals("yes")) {
					System.out.println("层深 校验通过,层深 名称="
							+ entityBeanoc_depthlist.getDepth());
					e0.setOc_deplist_id(entityBeanoc_depthlist.getId());// 设置了一个深度数据
				} else {
					System.out.println("层深 校验通过,层深 名称="
							+ entityBeanoc_depthlist.getDepth());
					return null;
				}// 层深校验完成

				for (int property_id = 7; property_id < column - 1; property_id++) {
					cell = sheet.getCell(property_id, i);
					String cellproperty = cell.getContents();
					Integer kh_1 = cellproperty.indexOf("(");
					Integer kh_2 = cellproperty.indexOf(")");
					if (kh_1 == -1 || kh_2 == -1) {
						System.out.println("属性值中缺少工具内容");
						return null;
					}
					valuekey = Double.valueOf(cellproperty.substring(0, kh_1));
					String property_tool = cellproperty.substring(kh_1 + 1,
							kh_2);
					// System.out.println("属性的值="+valuekey);
					// System.out.println("属性工具名称="+property_tool);
					oc_property_ice = propertylist_table.get(property_id - 7);
					Integer pid = propertylist_table.get(property_id - 7)
							.getId();
					// System.out.println("属性的PID="+pid);
					String find_property_tools = "not";
					for (int ch_property_tool_id = 0; ch_property_tool_id < propertytoolslist
							.size(); ch_property_tool_id++) {
						// System.out.println(propertytoolslist.get(ch_property_tool_id).getTools_name());
						// System.out.println(propertytoolslist.get(ch_property_tool_id).getPid());
						if (propertytoolslist.get(ch_property_tool_id).getPid()
								.equals(pid)
								&& propertytoolslist.get(ch_property_tool_id)
										.getTools_name().equals(property_tool)) {
							find_property_tools = "yes";
							oc_property_tools_ice = propertytoolslist
									.get(ch_property_tool_id);
							break;
						}
					}
					if (find_property_tools.equals("yes")) {
						EnitityBeanOc_Date_Ice Oc_Date_Ice = new EnitityBeanOc_Date_Ice();
						Oc_Date_Ice.setDel("OFF");
						Oc_Date_Ice.setOc_deplist_id(e0.getOc_deplist_id());
						Oc_Date_Ice.setOc_voyage_id(e0.getOc_voyage_id());
						Oc_Date_Ice.setOc_station_id(e0.getOc_station_id());
						Oc_Date_Ice.setOc_property_id(oc_property_ice.getId());
						Oc_Date_Ice
								.setOc_property_tools_id(oc_property_tools_ice
										.getId());
						Oc_Date_Ice.setValue_key(valuekey);
						Oc_Date_Ice.setOc_xls_upload(0);
						System.out.println("为录入的表单增加了一个数据"
								+ Oc_Date_Ice.Read_Me());
						Date_list.add(Oc_Date_Ice);
					} else {
						System.out.println("未能发现合适的属性测量工具,期待的值="
								+ property_tool);
						return null;
					}

				}

				// 按照条件搜索站点名称 找到为有效 没找到就是无效

			}

			System.out.println("数据分析结束,开始记录到数据库中...");

			System.out.println("需要录入的数据为=" + Date_list.size());
			EntityBeanL_Sequence L_DATE = this.service_public
					.Find_L_Sequence_By_seq_Name("SEQ_OC_DATE_ICE");
			Integer id_date = L_DATE.getSeq_Value() + 1;
			for (int install = 0; install < Date_list.size(); install++) {
				Date_list.get(install).setOc_xls_upload(e.getId());
				Date_list.get(install).setId(id_date);

				id_date = id_date + 1;
				this.service_admin.Insert_Oc_Data_Ice(Date_list.get(install));
			}
			L_DATE.setSeq_Value(id_date);
			this.service_public.Update_L_Sequence(L_DATE);

		} else if (e.getDate_num().equals("浮游生物")) {
			this.service_admin.Delete_Oc_Data_Pla_By_Xls(e.getId().toString());
			System.out.println("开始读取数据，导入工序");

			// 开始读取数据，导入工序
			// 读取所有的站点，放入内存。
			// 读取所有的属性，放入内存。
			// 开始读取行。
			// 分析行的前几列，并在站点表中比对，如果存在则通过 不存在则放弃。
			//
			EnitityBeanOc_Voyage_Pla enititybeanoc_voyage = new EnitityBeanOc_Voyage_Pla();// 校验用实例名
			EntityBeanOc_Depthlist_Pla oc_depthlist = new EntityBeanOc_Depthlist_Pla();// 校验用实例名
			EntityBeanOc_Station_Pla oc_station = new EntityBeanOc_Station_Pla();// 校验用实例名
			EntityBean_Oc_Property_Tools_Pla oc_property_tools = new EntityBean_Oc_Property_Tools_Pla();// 检查时的赋值对象
			EntityBean_Oc_Property_Pla oc_property = new EntityBean_Oc_Property_Pla();// 检查时的赋值对象
			Double valuekey;// 检查时的赋值对象
			List<EnitityBeanOc_Voyage_Pla> voyagelist = this.service_admin
					.Find_Oc_Voyage_Pla_By_boatid(Integer.valueOf(e
							.getBoat_id()));// 按照科考船读取数据

			System.out.println("根据科考船的数据获得了航次的大小=" + voyagelist.size());
			List<EntityBeanOc_Depthlist_Pla> depthlist = this.service_admin
					.Find_EntityBeanOc_Depthlist_Pla();

			System.out.println("根据科考船的数据获得了层深的大小=" + depthlist.size());
			List<EntityBeanOc_Station_Pla> stationlist = new ArrayList<EntityBeanOc_Station_Pla>();

			stationlist = this.service_admin.Find_Oc_Station_Pla_is_active();// 获取了所有的有效站点
			System.out.println("获取了所有的有效站点的大小=" + stationlist.size());
			List<EntityBean_Oc_Property_Pla> propertylist = this.service_admin
					.Find_EntityBean_Oc_Property_Pla_by_property_kind(7);
			List<String> propertyliststr = new ArrayList<String>();
			List<EntityBean_Oc_Property_Pla> propertylist_table = new ArrayList<EntityBean_Oc_Property_Pla>();// 记录在本表中使用到的属性值
			for (int i = 0; i < propertylist.size(); i++) {
				propertyliststr.add(propertylist.get(i).getProperty_name());
				System.out.println(propertylist.get(i).getProperty_name());
			}

			System.out.println("根据科考船的数据获得了属性的大小=" + propertylist.size());
			List<EntityBean_Oc_Property_Tools_Pla> propertytoolslist = this.service_admin
					.Find_EntityBean_Oc_Property_Tools_Pla_Is_Active();

			/*
			 * List<String>propertytoolsliststr=new ArrayList<String>(); for(int
			 * i=0;i<propertytoolslist.size();i++) {
			 * propertytoolsliststr.add(propertytoolslist
			 * .get(i).getTools_name());
			 * System.out.println(propertytoolslist.get(i).getTools_name()); }
			 */
			System.out
					.println("根据科考船的数据获得了属性工具的大小=" + propertytoolslist.size());
			Workbook workBook = null;
			InputStream is = new FileInputStream(e.getFile_path());// 读取上传的xls文件
			workBook = Workbook.getWorkbook(is);
			// 从0开始，第一张工作表
			Sheet sheet = workBook.getSheet(0);
			int row = sheet.getRows();
			int column = sheet.getColumns();
			if (column < 7) {
				System.out.println("表格宽度有问题,怀疑文件格式错误");
				return null;
			}
			System.out.println("row=" + row);
			System.out.println("column=" + column);
			System.out.println("检查表头宽度");
			// 航次 站位 经度(E) 纬度(N) 采样时间(年-月-日-时:分) 深度（m） 层（m） 压强(db) 温度(deg C)
			// 盐度(PSU)
			// 潜在温度(deg C) 潜在密度(Kg/m^3) 溶解氧(μM) 硝酸盐(μM) 磷酸盐(μM) 硅酸盐(μM)
			// 氨盐(μM) 亚硝酸盐(μM) 初级生产力(mgC﹒m-3h-1) δ18O(‰) 备注
			List<String> liststr = new ArrayList<String>();
			liststr.add("航次");
			liststr.add("站位");
			liststr.add("经度(E)");
			liststr.add("纬度(N)");
			liststr.add("采样时间(年-月-日-时:分)");
			liststr.add("深度(m)");
			liststr.add("层(m)");
			for (int i = 0; i < 7; i++) {
				Cell cell = sheet.getCell(i, 0);
				if (!cell.getContents().toString().equals(liststr.get(i))) {
					System.out.println("表头数据有错误,期待的值=" + liststr.get(i));
					return null;// 返回错误的页面并告知错误
				}
			}
			for (int i = 7; i < column - 1; i++) {
				Cell cell = sheet.getCell(i, 0);
				String cellstr = cell.getContents().toString();
				Integer kh = cellstr.indexOf("(");
				cellstr = cellstr.substring(0, kh);
				System.out.println("cellstr=" + cellstr);
				if (!propertyliststr.contains(cellstr)) {
					System.out.println("系统中没有这个有效参数,查看有无 " + cellstr + " 属性");
					return null;
				} else {
					// 在propertylist_table增加相应的数据
					EntityBean_Oc_Property_Pla property_table = new EntityBean_Oc_Property_Pla();
					for (int ck_cellstr = 0; ck_cellstr < propertylist.size(); ck_cellstr++) {
						if (cellstr.equals(propertylist.get(ck_cellstr)
								.getProperty_name())) {
							property_table = propertylist.get(ck_cellstr);
							propertylist_table.add(property_table);
						}
					}
				}
			}
			System.out.println("在导入的XLS文件中,使用的属性大小="
					+ propertylist_table.size());
			Cell cell = sheet.getCell(column - 1, 0);
			String cellstr = cell.getContents().toString();

			if (!cellstr.equals("备注")) {
				System.out.println("最后一列不是备注列,期待的值=备注");
				return null;
			}
			System.out.println("表格头部校验完成,开始校验表格数据");
			// 忽略了英文的标题，从第三列开始读取数据
			List<EnitityBeanOc_Date_Pla> Date_list = new ArrayList<EnitityBeanOc_Date_Pla>();// 生成一个需要最后写入到数据库的字段
			for (int i = 2; i < row; i++) {
				EnitityBeanOc_Date_Pla e0 = new EnitityBeanOc_Date_Pla();
				// 校验航次
				cell = sheet.getCell(0, i);
				String voyagename = cell.getContents().toString();
				String find_voyage = "not";
				for (int voyage_id = 0; voyage_id < voyagelist.size(); voyage_id++) {
					if (voyagelist.get(voyage_id).getVoyage_name().equals(
							voyagename)) {
						enititybeanoc_voyage = voyagelist.get(voyage_id);
						find_voyage = "yes";
						break;
					}
				}
				if (find_voyage.equals("yes")) {
					System.out.println("航次校验通过,航次名称="
							+ enititybeanoc_voyage.getVoyage_name());
					e0.setOc_voyage_id(enititybeanoc_voyage.getId());// 设置了一个航次数据
				} else {
					System.out.println("未能发现正确的航次名称,期待的值=" + voyagename);
					return null;
				}
				// 航次校验完成，开始校验站点
				EntityBeanOc_Station_Pla e_station = new EntityBeanOc_Station_Pla();
				cell = sheet.getCell(1, i);
				e_station.setStation_name(cell.getContents());
				cell = sheet.getCell(2, i);
				e_station.setLongitude(cell.getContents());
				cell = sheet.getCell(3, i);
				e_station.setDimensionality(cell.getContents());
				cell = sheet.getCell(5, i);
				e_station.setDepth(Double.valueOf(cell.getContents()));
				String find_station = "not";
				for (int find_station_id = 0; find_station_id < stationlist
						.size(); find_station_id++) {
					/*
					 * System.out.println("站点名称="+stationlist.get(find_station_id
					 * ).getStation_name());
					 * System.out.println("站点深度="+stationlist
					 * .get(find_station_id).getDepth());
					 * System.out.println("站点经度="
					 * +stationlist.get(find_station_id).getDimensionality());
					 * System
					 * .out.println("站点维度="+stationlist.get(find_station_id
					 * ).getLongitude());
					 * 
					 * 
					 * System.out.println("比较站点名称="+e_station.getStation_name());
					 * System.out.println("比较站点深度="+e_station.getDepth());
					 * System
					 * .out.println("比较站点经度="+e_station.getDimensionality());
					 * System.out.println("比较站点维度="+e_station.getLongitude());
					 */
					if (stationlist.get(find_station_id).getStation_name()
							.equals(e_station.getStation_name())
							&& stationlist.get(find_station_id).getDepth() == e_station
									.getDepth()
							&& stationlist.get(find_station_id)
									.getDimensionality().equals(
											e_station.getDimensionality())
							&& stationlist.get(find_station_id).getLongitude()
									.equals(e_station.getLongitude())) {
						find_station = "yes";
						e_station = stationlist.get(find_station_id);
						e0.setOc_station_id(e_station.getId());// 设置了站点值
						break;
					}
				}
				if (find_station.equals("yes")) {
					System.out.println("站点校验通过,站点名称="
							+ e_station.getStation_name());
				} else {
					System.out.println("未能发现正确的站点名称,期待的值="
							+ e_station.getStation_name());
					return null;
				}// 站点校验完成
				cell = sheet.getCell(6, i);
				EntityBeanOc_Depthlist_Pla entityBeanoc_depthlist = new EntityBeanOc_Depthlist_Pla();
				entityBeanoc_depthlist.setDepth(Integer.valueOf(cell
						.getContents()));
				String find_depthlist = "not";
				for (int deplist_id = 0; deplist_id < depthlist.size(); deplist_id++) {
					if (entityBeanoc_depthlist.getDepth().equals(
							depthlist.get(deplist_id).getDepth())) {
						find_depthlist = "yes";
						entityBeanoc_depthlist = depthlist.get(deplist_id);
						break;
					}
				}
				if (find_depthlist.equals("yes")) {
					System.out.println("层深 校验通过,层深 名称="
							+ entityBeanoc_depthlist.getDepth());
					e0.setOc_deplist_id(entityBeanoc_depthlist.getId());// 设置了一个深度数据
				} else {
					System.out.println("层深 校验通过,层深 名称="
							+ entityBeanoc_depthlist.getDepth());
					return null;
				}// 层深校验完成

				for (int property_id = 7; property_id < column - 1; property_id++) {
					cell = sheet.getCell(property_id, i);
					String cellproperty = cell.getContents();
					Integer kh_1 = cellproperty.indexOf("(");
					Integer kh_2 = cellproperty.indexOf(")");
					if (kh_1 == -1 || kh_2 == -1) {
						System.out.println("属性值中缺少工具内容");
						return null;
					}
					valuekey = Double.valueOf(cellproperty.substring(0, kh_1));
					String property_tool = cellproperty.substring(kh_1 + 1,
							kh_2);
					// System.out.println("属性的值="+valuekey);
					// System.out.println("属性工具名称="+property_tool);
					oc_property = propertylist_table.get(property_id - 7);
					Integer pid = propertylist_table.get(property_id - 7)
							.getId();
					// System.out.println("属性的PID="+pid);
					String find_property_tools = "not";
					for (int ch_property_tool_id = 0; ch_property_tool_id < propertytoolslist
							.size(); ch_property_tool_id++) {
						// System.out.println(propertytoolslist.get(ch_property_tool_id).getTools_name());
						// System.out.println(propertytoolslist.get(ch_property_tool_id).getPid());
						if (propertytoolslist.get(ch_property_tool_id).getPid()
								.equals(pid)
								&& propertytoolslist.get(ch_property_tool_id)
										.getTools_name().equals(property_tool)) {
							find_property_tools = "yes";
							oc_property_tools = propertytoolslist
									.get(ch_property_tool_id);
							break;
						}
					}
					if (find_property_tools.equals("yes")) {
						EnitityBeanOc_Date_Pla Oc_Date_Sur = new EnitityBeanOc_Date_Pla();
						Oc_Date_Sur.setDel("OFF");
						Oc_Date_Sur.setOc_deplist_id(e0.getOc_deplist_id());
						Oc_Date_Sur.setOc_voyage_id(e0.getOc_voyage_id());
						Oc_Date_Sur.setOc_station_id(e0.getOc_station_id());
						Oc_Date_Sur.setOc_property_id(oc_property.getId());
						Oc_Date_Sur.setOc_property_tools_id(oc_property_tools
								.getId());
						Oc_Date_Sur.setValue_key(valuekey);
						Oc_Date_Sur.setOc_xls_upload(0);
						System.out.println("为录入的表单增加了一个数据"
								+ Oc_Date_Sur.Read_Me());
						Date_list.add(Oc_Date_Sur);
					} else {
						System.out.println("未能发现合适的属性测量工具,期待的值="
								+ property_tool);
						return null;
					}

				}

				// 按照条件搜索站点名称 找到为有效 没找到就是无效

			}

			System.out.println("数据分析结束,开始记录到数据库中...");

			System.out.println("需要录入的数据为=" + Date_list.size());
			EntityBeanL_Sequence L_DATE = this.service_public
					.Find_L_Sequence_By_seq_Name("SEQ_OC_DATE_PLA");
			Integer id_date = L_DATE.getSeq_Value() + 1;
			for (int install = 0; install < Date_list.size(); install++) {
				Date_list.get(install).setOc_xls_upload(e.getId());
				Date_list.get(install).setId(id_date);

				id_date = id_date + 1;
				this.service_admin.Insert_Oc_Data_Pla(Date_list.get(install));
			}
			L_DATE.setSeq_Value(id_date);
			this.service_public.Update_L_Sequence(L_DATE);

		}
		String sql = "select * from OC_XLS_UPLOAD order by id DESC";
		System.out.println("SQL=" + sql);
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(datarecoverform.getRowcountperpage()), Integer
						.valueOf(datarecoverform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Recover> list = interfaceforresultsettolist
				.ViewOc_Data_Recover(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("datarecoverform", datarecoverform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_import_recover(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		DataRecoverForm datarecoverform = (DataRecoverForm) form;
		String id = datarecoverform.getId();
		System.out.println("ID=" + id);
		id = this.cut_tail(id);
		List<Oc_Xls_Upload> oc_xls_upload = this.service_admin
				.Find_Oc_Xls_Upload(id);
		for (int i = 0; i < oc_xls_upload.size(); i++) {
			Oc_Xls_Upload e = oc_xls_upload.get(i);

			if (e.getDate_num().equals("海洋环境")) {
				this.service_admin.Delete_Oc_Data_Sur_By_Xls(e.getId()
						.toString());
			} else if (e.getDate_num().equals("底栖环境")) {
				this.service_admin.Delete_Oc_Data_Ben_By_Xls(e.getId()
						.toString());
			} else if (e.getDate_num().equals("海冰生态")) {
				this.service_admin.Delete_Oc_Data_Ice_By_Xls(e.getId()
						.toString());
			} else if (e.getDate_num().equals("浮游生物")) {
				this.service_admin.Delete_Oc_Data_Pla_By_Xls(e.getId()
						.toString());

			}

		}

		String sql = "select * from OC_XLS_UPLOAD order by id DESC";
		System.out.println("SQL=" + sql);
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(datarecoverform.getRowcountperpage()), Integer
						.valueOf(datarecoverform.getCurrentpage()),
				"loadrichtext()");
		InterfaceForResultSetToList interfaceforresultsettolist = new InterfaceForResultSetToList();
		List<ViewOc_Data_Recover> list = interfaceforresultsettolist
				.ViewOc_Data_Recover(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("datarecoverform", datarecoverform);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}
}
